/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * DrawStrategyPanel.java
 *
 * Created on Jul 14, 2010, 10:49:52 PM
 */

package taikai.draws;

import org.jdesktop.application.Action;

/**
 *
 * @author jeffmartin
 */
public class DrawStrategyPanel extends javax.swing.JPanel {
    private final DrawStrategy strategy;
    private DrawStrategySelectionPanel generate;

    /** Creates new form DrawStrategyPanel */
    public DrawStrategyPanel(DrawStrategy strategy) {
        initComponents();
        this.strategy = strategy;
        name.setText(strategy.getName());
        updateRunningTime();
    }

    private void updateRunningTime() {
        runningTime.setText(strategy.getEstimatedRunningTime());
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        name = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        runningTime = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        matchLength = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        changeOverTime = new javax.swing.JTextField();

        setBorder(javax.swing.BorderFactory.createEtchedBorder());
        setName("Form"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(taikai.TaikaiApplication.class).getContext().getResourceMap(DrawStrategyPanel.class);
        name.setText(resourceMap.getString("name.text")); // NOI18N
        name.setName("name"); // NOI18N

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        runningTime.setText(resourceMap.getString("runningTime.text")); // NOI18N
        runningTime.setName("runningTime"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(taikai.TaikaiApplication.class).getContext().getActionMap(DrawStrategyPanel.class, this);
        jButton1.setAction(actionMap.get("close")); // NOI18N
        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setName("jButton1"); // NOI18N

        matchLength.setColumns(4);
        matchLength.setText(resourceMap.getString("matchLength.text")); // NOI18N
        matchLength.setName("matchLength"); // NOI18N
        matchLength.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                keyTypes(evt);
            }
        });

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        changeOverTime.setColumns(4);
        changeOverTime.setName("changeOverTime"); // NOI18N
        changeOverTime.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                keyTypes(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(name)
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jLabel3)
                            .add(jLabel1)
                            .add(jLabel2))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(runningTime)
                            .add(matchLength, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(changeOverTime, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(42, Short.MAX_VALUE))
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .addContainerGap(133, Short.MAX_VALUE)
                .add(jButton1)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(name)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel1)
                    .add(matchLength, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel3)
                    .add(changeOverTime, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel2)
                    .add(runningTime))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(jButton1)
                .add(35, 35, 35))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void keyTypes(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_keyTypes
        try {
            strategy.setMatchLength(Integer.parseInt(matchLength.getText()));
        }catch(Exception e) {}
        try {
            strategy.setChangeOverTime(Integer.parseInt(changeOverTime.getText()));
        }catch(Exception e) {}

        updateRunningTime();
    }//GEN-LAST:event_keyTypes


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField changeOverTime;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JTextField matchLength;
    private javax.swing.JLabel name;
    private javax.swing.JLabel runningTime;
    // End of variables declaration//GEN-END:variables

    @Action
    public void close() {
        getGenerate().close(strategy);
    }

    /**
     * @return the generate
     */
    public DrawStrategySelectionPanel getGenerate() {
        return generate;
    }

    /**
     * @param generate the generate to set
     */
    public void setGenerate(DrawStrategySelectionPanel generate) {
        this.generate = generate;
    }

}
